package com.itheima.app.controller.umsController;

import com.itheima.app.manager.umsManager.UmsAdminManager;
import com.itheima.app.manager.umsManager.UmsMenuManager;
import com.itheima.commons.R;
import com.itheima.domain.db.ums.UmsAdmin;
import com.itheima.domain.db.ums.UmsMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author DogeGuo
 */
@RestController
public class UmsMenuController {
    @Autowired
    UmsMenuManager umsMenuManager;

    /*
     * 分页查询用户信息
     * */
    @GetMapping("/menu/list/{parentId}")
    public R findByPage(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize,
            @PathVariable Long parentId){

        return umsMenuManager.findByPage(pageNum,pageSize,parentId);

    }


    /*
    *添加后台菜单
    * */
    @PostMapping("/menu/create")
    public R addUsmMenu(@RequestBody UmsMenu umsMenu){
        return umsMenuManager.addUsmMenu(umsMenu);
    }

    /*
     *根据ID删除后台菜单
     * */
    @PostMapping("/menu/delete/{id}")
    public R deleteById(@PathVariable Long id){
        return umsMenuManager.deleteById(id);
    }

    // 树状返回所有菜单列表
    @GetMapping("/menu/treeList")
    public R findMenuTreeList() {
        return umsMenuManager.findMenuTreeList();
    }


    /*
     *修改后台菜单
     * */
    @PostMapping("/menu/update/{id}")
    public R updateById(@PathVariable Long id,@RequestBody UmsMenu umsMenu){
        return umsMenuManager.updateById(id,umsMenu);
    }


    // 根据菜单id获取详情
    @GetMapping("/menu/{id}")
    public R findMenuById(@PathVariable Long id) {
        return umsMenuManager.findMenuById(id);
    }

    // 修改菜单显示状态
    @PostMapping("/menu/updateHidden/{id}")
    public R updateMenuHidden(@PathVariable Long id, Integer hidden) {
        return umsMenuManager.updateMenuHidden(id, hidden);
    }
}
